#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,v,d[1000000],vi[1000],a[1000];
int p[1000000],c[1000],s[1000000],sum1,sum2;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    while(t){
        scanf("%d%d%d%d",&n,&m,&l,&v);  //l:changdu   xiansu
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&d[i],&vi[i],&a[i]);  //shiru  chushi   jiasu
            if(a[i]!=0){
                c[i]=(3*3-vi[i]*vi[i])/(2*a[i])+1;
            }
        }
        if(a[0]==a[1]==a[2]){
            for(int i=0;i<n;i++){
                if(vi[i]>v){
                    sum1++;
                }
            }
            if(sum1==0){
                cout<<sum1<<" "<<m<<endl;
            }
            else{
                cout<<sum1<<" "<<m-1<<endl;
            }
            return 0;
        }
        for(int i=0;i<m;i++){
            scanf("%d",&p[i]);  //cesu
        }
        for(int i=0;i<n;i++){
            if(d[i]+c[i]<=p[m-1]){
                sum1++;
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(a[i]==0){
                    continue;
                }
                else{
                    if(a[i]<0&&p[j]>=c[i]+d[i]){
                        s[j-1]++;
                    }
                    else if(a[i]>0&&p[j]>=c[i]+d[i]){
                        s[j]++;
                    }
                }
            }
        }
        for(int i=0;i<m;i++){
            if(s[i]!=0){
                sum2++;
            }
        }

        if(sum1==0){
            cout<<sum1<<" "<<m<<endl;
        }
        else{
            cout<<sum1<<" "<<sum2<<endl;
        }
        t--;
        sum1=0;
        sum2=0;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
